home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS01.ADF / C / decvnt.c < prev    next >
C/C++ Source or Header  |  1985-11-16  |  2KB  |  80 lines

  1.  
  2. /* decvnt.c */
  3.  
  4. /****************************************************************/
  5. /*                                                              */
  6. /* program to reverse the operation of "convert" for the Amiga  */
  7. /* used to counteract the effect of BBS systems which can't take*/
  8. /* binary files                                                 */
  9. /* This program was originally compiled by Microsoft C 3.0      */
  10. /*      compile as:     msc decnvt;                             */
  11. /*      link as:        link decnvt+\msc\lib\binmode;           */
  12. /*                                                              */
  13. /* Copyright(c) 1985 Michael G. Lehman                          */
  14. /* Freely distribute but All Rights still reserved              */
  15. /*                                                              */
  16. /****************************************************************/
  17.  
  18. /* converted to Lattice by John Foust, the AMICUS Network */
  19.  
  20. /* define one of these */
  21. #define LATTI
  22. #undef MSC30
  23.  
  24. #include <stdio.h>
  25. #include <fcntl.h>
  26.  
  27. #ifdef MSC30
  28. #include <sys\types.h>
  29. #include <sys\stat.h>
  30. #include <io.h>
  31. #endif
  32.  
  33. char buf[256];
  34. unsigned char bytes[128];
  35.  
  36. FILE *in;
  37. int out;
  38.  
  39. main(argc,argv)
  40. int argc;
  41. char **argv;
  42. {
  43.   int i,j;
  44.   char *p;
  45.  
  46.   in = fopen(argv[1],"r");
  47.  
  48. #ifdef MSC30
  49.   out= open(argv[2],O_TRUNC | O_WRONLY | O_BINARY | O_CREAT , S_IWRITE);
  50. #endif
  51. #ifdef LATTI
  52.   out= open(argv[2],O_TRUNC | O_WRONLY | O_RAW | O_CREAT );
  53. #endif
  54.  
  55.   while(1)
  56.         {
  57.                 fread(buf,sizeof(buf),1,in);
  58.                 for(i=0,j=0; buf[i] != '\n' && buf[i] != 'Q' && i < sizeof(buf); i++)
  59.                   {
  60.                         bytes[j] = (cnv(buf[i++]) << 4);
  61.                         bytes[j++] |= cnv(buf[i]);
  62.                   }
  63.                 write(out,bytes,j);
  64.                 if (buf[i] == 'Q')
  65.                   break;
  66.         }
  67.   fclose(in);
  68.   close(out);
  69. }
  70.  
  71.  
  72. int cnv(ch)
  73. char ch;
  74. {
  75.   if (ch >= '0' && ch <= '9')
  76.     return(ch-'0');
  77.   else
  78.     return((ch-'A')+10);
  79. }
  80.